//
//  ZLWrongParsingTableQuestionListCell.m
//  ZLExamination
//
//  Created by Zheng on 2017/9/13.
//  Copyright © 2017年 Zheng. All rights reserved.
//

#import "ZLWrongParsingTableQuestionListCell.h"
#import "ZLExamResultModel.h"

@implementation ZLWrongParsingTableQuestionListCell


- (void)setModel:(ZLExamResultListModel *)model {
    _model = model;
    
    if (_model.type.integerValue == 1) {
        //单选
        _optionsLbl = [self getOptionsLblWithIsTypeOfAnswer:_type];
        
        [self.contentView addSubview:_optionsLbl];
        [self.contentView addSubview:self.questionLbl];
        
        [_optionsLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(8);
            make.left.mas_equalTo(12);
            make.width.height.mas_equalTo(30);
        }];
        
        [_questionLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_optionsLbl.mas_top).offset(-4);
            make.left.equalTo(_optionsLbl.mas_right).offset(15);
            make.bottom.mas_equalTo(-10);
            make.right.mas_equalTo(-12);
            make.height.greaterThanOrEqualTo(@40);
        }];
    } else {
        //多选
        _optionsLbl = nil;
        _optionsLbl = [self getMultipleOptionsLblWithIsTypeOfAnswer:_type];
        
        [self.contentView addSubview:_optionsLbl];
        [self.contentView addSubview:self.questionLbl];
        
        [_optionsLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(8);
            make.left.mas_equalTo(12);
            make.width.height.mas_equalTo(30);
        }];
        
        [_questionLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_optionsLbl.mas_top).offset(-4);
            make.left.equalTo(_optionsLbl.mas_right).offset(15);
            make.bottom.mas_equalTo(-10);
            make.right.mas_equalTo(-12);
            make.height.greaterThanOrEqualTo(@40);
        }];
    }
}


#pragma mark - 初始化
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (UILabel *)questionLbl {
    if (!_questionLbl) {
        _questionLbl = [[UILabel alloc] init];
        _questionLbl.font = kMyFont(15);
        _questionLbl.textColor = [UIColor darkGrayColor];
        _questionLbl.numberOfLines = 0;
        [_questionLbl sizeToFit];
    }
    return _questionLbl;
}

#pragma mark - 获得单选选项
- (UILabel *)getOptionsLblWithIsTypeOfAnswer:(NSString *)type {
    UILabel *optionsLbl = [self layerSettingsWithCornerRadius:15 withTypeOfAnswer:type];
    return optionsLbl;
}

#pragma mark - 获得多选选项
- (UILabel *)getMultipleOptionsLblWithIsTypeOfAnswer:(NSString *)type {
    UILabel *optionsLbl = [self layerSettingsWithCornerRadius:5 withTypeOfAnswer:type];
    return optionsLbl;
}

- (UILabel *)layerSettingsWithCornerRadius:(CGFloat)radius withTypeOfAnswer:(NSString *)type {
    UILabel *optionsLbl = [[UILabel alloc] init];
    optionsLbl.layer.cornerRadius = radius;
    optionsLbl.textAlignment = NSTextAlignmentCenter;
    optionsLbl.layer.masksToBounds = YES;

    if (type.integerValue == 1) {
        //未作答
        optionsLbl.backgroundColor = [UIColor whiteColor];
        optionsLbl.layer.borderColor = [kMY_BLUE_COLOR CGColor];
        optionsLbl.layer.borderWidth = 0.5;
        optionsLbl.textColor = kMY_BLUE_COLOR;
    } else if (type.integerValue == 2) {
        //答对
        optionsLbl.layer.backgroundColor = [kRGB_COLOR(237, 40, 46, 1) CGColor];
        optionsLbl.textColor = [UIColor whiteColor];
    } else {
        //答错
        optionsLbl.backgroundColor = kMY_BLUE_COLOR;
        optionsLbl.textColor = [UIColor whiteColor];
    }
    
    return optionsLbl;
}

@end
